package com.sh.service;


import jakarta.mail.internet.MimeMessage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;


@Service
@Slf4j
public class MailBiz {

    @Value("${spring.mail.from}")
    private String from;

    @Autowired
    private JavaMailSender mailSender;

//    @Autowired
//    private WebSocket webSocket;

    @Async
    public void send( String content) {
        log.info("我是MailBiz的Send，我的线程是：{}" , Thread.currentThread().getName());
        MimeMessage mm = mailSender.createMimeMessage();
        MimeMessageHelper message = new MimeMessageHelper(mm, "utf-8");
        try {
            message.setFrom(from);
            message.setTo("1611543951@qq.com");
            message.setSubject("小萌神通知");
            message.setText(content, true);
            mailSender.send(mm);
        }catch (Exception e){
            System.out.println("发送邮件失败");
        }
    }
}
